Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[evm] EIP-1153 enable transient storage feature #4214

Merged
merged 19 commits into from
Apr 12, 2024
Merged

[evm] EIP-1153 enable transient storage feature #4214

merged 19 commits into from
Apr 12, 2024

Conversation

millken
Copy link
Contributor

@millken millken commented Mar 28, 2024

Description

Implemented EIP-1153

Fixes #4177

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@millken millken marked this pull request as draft March 28, 2024 09:02
@millken millken marked this pull request as ready for review March 29, 2024 02:18
@@ -259,7 +259,7 @@ func TestConstantinople(t *testing.T) {
},
{
"io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y",
1261440000, // = 200*365*24*3600/5, around 200 years later
39275560,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it must less genesis default UpernavikBlockHeight

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check past PR, you need to break it to 2 parts

after Tsunami - Upernavik {
}
after Upernavik {
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix now

function tload(uint location) public view returns (uint value) {
assembly {
value := tload(location)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transient storage is accessible to smart contracts via 2 new opcodes, TLOAD and TSTORE

refer: https://eips.ethereum.org/EIPS/eip-1153

Copy link

codecov bot commented Mar 29, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 76.75%. Comparing base (d716bb9) to head (46adced).
Report is 22 commits behind head on master.

❗ Current head 46adced differs from pull request most recent head 4b76ef0. Consider uploading reports for the commit 4b76ef0 to get more accurate results

Files Patch % Lines
action/protocol/execution/evm/evmstatedbadapter.go 91.42% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4214      +/-   ##
==========================================
+ Coverage   76.51%   76.75%   +0.24%     
==========================================
  Files         340      340              
  Lines       29273    29314      +41     
==========================================
+ Hits        22397    22501     +104     
+ Misses       5761     5707      -54     
+ Partials     1115     1106       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -530,6 +544,8 @@ func (stateDB *StateDBAdapter) Prepare(rules params.Rules, sender, coinbase comm
if !rules.IsBerlin {
return
}
// Clear out any leftover from previous executions
stateDB.accessList = newAccessList()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not necessary? we are creating a new StateDBAdpator for each tx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for safety, it's best to add

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the relationship with eip-1153?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for safety, it's best to add

for what kind of safety? We need to be clear what we want to achieve.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -547,6 +563,8 @@ func (stateDB *StateDBAdapter) Prepare(rules params.Rules, sender, coinbase comm
if rules.IsShanghai { // EIP-3651: warm coinbase
stateDB.AddAddressToAccessList(coinbase)
}
// Reset transient storage at the beginning of transaction execution
stateDB.transientStorage = newTransientStorage()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing, not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is best to add

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discused, let's remove this, it is done in NewStateDBAdapter

@@ -356,7 +356,8 @@ func TestConstantinople(t *testing.T) {
require.Equal(isSumatra, chainRules.IsShanghai)

// Cancun, Prague not yet enabled
require.False(evmChainConfig.IsCancun(big.NewInt(int64(e.height)), evm.Context.Time))
isUpernavik := g.IsUpernavik(e.height)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments need updates

sn := state.Snapshot()
state.SetTransientState(addr, key, value)
// the retrieved value should equal what was set
if got := state.GetTransientState(addr, key); got != value {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's be consistent with testing code style, use require.Equal(value, got)

// value is now the empty hash
state.RevertToSnapshot(sn)
if got, exp := state.GetTransientState(addr, key), (common.Hash{}); exp != got {
t.Fatalf("transient storage mismatch: have %x, want %x", got, exp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, use current testing code style

t.Fatalf("transient storage mismatch: have %x, want %x", got, value)
// reset transient state
state.SetTransientState(addr, key, value)
if got := state.GetTransientState(addr, key); got != value {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -677,6 +704,7 @@ func TestSnapshotRevertAndCommit(t *testing.T) {
// refund fix and accessList are introduced after fixSnapshot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment, add transient storage

@@ -701,7 +701,7 @@ func TestSnapshotRevertAndCommit(t *testing.T) {
require.Equal(3, len(stateDB.contractSnapshot))
require.Equal(3, len(stateDB.selfDestructedSnapshot))
require.Equal(3, len(stateDB.preimageSnapshot))
// refund fix and accessList are introduced after fixSnapshot
// refund fix and accessList、transient storage are introduced after fixSnapshot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems a chinese version comma

"rawReturnValue": "0000000000000000000000000000000000000000000000000000000000000003",
"comment": "call getAddress"
}]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add newline

@@ -701,7 +701,7 @@ func TestSnapshotRevertAndCommit(t *testing.T) {
require.Equal(3, len(stateDB.contractSnapshot))
require.Equal(3, len(stateDB.selfDestructedSnapshot))
require.Equal(3, len(stateDB.preimageSnapshot))
// refund fix and accessListtransient storage are introduced after fixSnapshot
// refund fix and accessList,transient storage are introduced after fixSnapshot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refund fix, accessList, and transient

@@ -257,6 +257,16 @@ func TestConstantinople(t *testing.T) {
action.EmptyAddress,
29275561,
},
// after Tsunami - Upernavik
{
action.EmptyAddress,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "io1pcg2ja9krrhujpazswgz77ss46xgt88afqlk6y"

@@ -257,6 +257,16 @@ func TestConstantinople(t *testing.T) {
action.EmptyAddress,
29275561,
},
// after Tsunami - Upernavik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this comment line should be at L255

Copy link

sonarcloud bot commented Apr 11, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
9.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@millken millken merged commit afbbbd2 into iotexproject:master Apr 12, 2024
2 of 3 checks passed
@millken millken deleted the issue4177-eip1153 branch April 12, 2024 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[evm] enable transient storage feature
4 participants